/*    main.cpp                                                                */
/*   ----------------------------------------------------------------------   */
/*    widgetpp - A simple C++ wrapper of DISLIN graphic library               */
/*                                                                            */
/*    Copyright (C) 2012  Mirko Cambi (email: mirko.cambi@gmail.com)          */
/*                                                                            */
/*    This program is free software: you can redistribute it and/or modify    */
/*    it under the terms of the GNU General Public License as published by    */
/*    the Free Software Foundation, either version 3 of the License, or       */
/*    (at your option) any later version.                                     */
/*                                                                            */
/*    This program is distributed in the hope that it will be useful,         */
/*    but WITHOUT ANY WARRANTY; without even the implied warranty of          */
/*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           */
/*    GNU General Public License for more details.                            */
/*                                                                            */
/*    You should have received a copy of the GNU General Public License       */
/*    along with this program.  If not, see <http://www.gnu.org/licenses/>.   */
/*                                                                            */
/*    #include <stdio.h>                                                      */
/*    #include <math.h>                                                       */
/*    #include "dislin.h"                                                     */
/*                                                                            */
/*    main()                                                                  */
/*    { int n = 100, i, ic;                                                   */
/*      double fpi = 3.1415926/180., step, x;                                 */
/*      float xray[100], y1ray[100], y2ray[100];                              */
/*                                                                            */
/*      step = 360. / (n-1);                                                  */
/*                                                                            */
/*      for (i = 0; i < n; i++)                                               */
/*      { xray[i] = i * step;                                                 */
/*        x = xray[i] * fpi;                                                  */
/*        y1ray[i] = sin(x);                                                  */
/*        y2ray[i] = cos(x);                                                  */
/*      }                                                                     */
/*                                                                            */
/*      disini();                                                             */
/*      pagera();                                                             */
/*      complx();                                                             */
/*      axspos(450,1800);                                                     */
/*      axslen(2200,1200);                                                    */
/*                                                                            */
/*      name("X-axis","x");                                                   */
/*      name("Y-axis","y");                                                   */
/*                                                                            */
/*      labdig(-1,"x");                                                       */
/*      ticks(9,"x");                                                         */
/*      ticks(10,"y");                                                        */
/*                                                                            */
/*      titlin("Demonstration of CURVE",1);                                   */
/*      titlin("SIN(X), COS(X)",3);                                           */
/*                                                                            */
/*      ic=intrgb(0.95,0.95,0.95);                                            */
/*      axsbgd(ic);                                                           */
/*                                                                            */
/*      graf(0.,360.,0.,90.,-1.,1.,-1.,0.5);                                  */
/*      setrgb(0.7,0.7,0.7);                                                  */
/*      grid(1,1);                                                            */
/*                                                                            */
/*      color("fore");                                                        */
/*      height(50);                                                           */
/*      title();                                                              */
/*                                                                            */
/*      color("red");                                                         */
/*      curve(xray,y1ray,n);                                                  */
/*      color("green");                                                       */
/*      curve(xray,y2ray,n);                                                  */
/*      disfin();                                                             */
/*    }                                                                       */

#include <cmath>
#include "Widgetpps.hpp"

using namespace std;
using namespace wdgpp;

class draw_function
{
public:
   draw_function(): xray(100), y1ray(100), y2ray(100)
   {
      const int n = xray.size();
      const double fpi = 3.1415926 / 180.;
      const double step = 360. / (n - 1);

      for(int i = 0; i < n; ++i) {
         xray[i] = i * step;
         double x = xray[i] * fpi;
         y1ray[i] = sin(x);
         y2ray[i] = cos(x);
      } 
   }

   void operator()() const
   {   
      set_color(colors::red);
      curve(xray, y1ray);
      set_color(colors::green);
      curve(xray, y2ray);
   }
private:
   std::vector<float> xray, y1ray, y2ray;
};

int main()
{
   WdgTitle title;
   title.set_line(0, "Demonstration of CURVE");
   title.set_line(2, "SIN(X), COS(X)");

   Wdg2DAxis axis;
   axis.set_name("X-axis", "Y-axis");
   axis.set_ticks(9, 10);
   
   Wdg2DPlot doc;
   doc.init();
   doc.set_title(&title);
   doc.set_axis(&axis);
   doc.set_draw_function(draw_function());
   doc.set_position(450, 1800);
   doc.set_lenght(2200, 1200);
   doc.cartesian_axis(0., 360., 0., 90., -1., 1., -1., 0.5);
   doc.draw();
   doc.close();
   
   return 0;
}

